package gcj2013.qual;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;

import org.korifey.ffalg.NumberTheory;
import org.korifey.ffalg.Probabilities;

import common.AbstractRunner;
import common.AbstractRunner.SIZE;

public class C extends AbstractRunner {
	
	static long a[] = new long[] {
		1
		,4
		,9
		,121
		,484
		,10201
		,12321
		,14641
		,40804
		,44944
		,1002001
		,1234321
		,4008004
		,100020001
		,102030201
		,104060401
		,121242121
		,123454321
		,125686521
		,400080004
		,404090404
		,10000200001l
		,10221412201l
		,12102420121l
		,12345654321l
		,40000800004l
		,1000002000001l
		,1002003002001l
		,1004006004001l
		,1020304030201l
		,1022325232201l
		,1024348434201l
		,1210024200121l
		,1212225222121l
		,1214428244121l
		,1232346432321l
		,1234567654321l
		,4000008000004l
		,4004009004004l
		,100000020000001l
		,100220141022001l
		,102012040210201l
		,102234363432201l
		,121000242000121l
		,121242363242121l
		,123212464212321l
		,123456787654321l
		,400000080000004l
	};
	
	
	@Override
	public void handleCase(int caseNumber) throws Exception {		
	    	long aa = scanner.nextLong();
	    	long bb = scanner.nextLong();
	    	int res = 0;
	    	for (int i=0; i<a.length; i++) {
	    		if (a[i] >= aa && a[i] <= bb) res++;
	    	}
	    	out.write(res+"\n");
		
// To generate from OEIS A002779 sequence
//		int n = 93;
//		long[] a = new long[n];
//		int res = 0;
//		cycle: for (int i=0; i<69; i++) {
//			long x = scanner.nextLong();
//			x = scanner.nextLong();
//			String y = Math.round(Math.sqrt(x))+"";
//			for (int j=0; j<y.length()/2; j++) {
//				if (y.charAt(j) != y.charAt(y.length()-1-j)) {
//					continue cycle;
//				}
//			}
//			a[res++] = x;
//			out.write(x+"\n,");
//		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		new C().init(SIZE.large).execute();
	}

}
